/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
define(["require", "exports", "./languageModeIds"], function (require, exports, languageModeIds) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * When clause context set when the current file is managed by vscode's built-in typescript extension.
     */
    const isManagedFile_contextName = 'typescript.isManagedFile';
    class ManagedFileContextManager {
        constructor(normalizePath, vscode) {
            this.normalizePath = normalizePath;
            this.vscode = vscode;
            this.isInManagedFileContext = false;
            this.onDidChangeActiveTextEditorSub = vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this);
            this.onDidChangeActiveTextEditor(vscode.window.activeTextEditor);
        }
        dispose() {
            this.onDidChangeActiveTextEditorSub.dispose();
        }
        onDidChangeActiveTextEditor(editor) {
            if (editor) {
                const isManagedFile = isSupportedLanguageMode(editor.document, this.vscode) && this.normalizePath(editor.document.uri) !== null;
                this.updateContext(isManagedFile);
            }
        }
        updateContext(newValue) {
            if (newValue === this.isInManagedFileContext) {
                return;
            }
            this.vscode.commands.executeCommand('setContext', isManagedFile_contextName, newValue);
            this.isInManagedFileContext = newValue;
        }
    }
    exports.default = ManagedFileContextManager;
    function isSupportedLanguageMode(doc, vscode) {
        return vscode.languages.match([languageModeIds.typescript, languageModeIds.typescriptreact, languageModeIds.javascript, languageModeIds.javascriptreact], doc) > 0;
    }
});
